﻿using System;
using nRoute.Components.Composition;
using nRoute.Utilities;

namespace nRoute.ViewModels
{
    public class ViewModelProvider
		 : IViewModelProvider
    {
        private readonly ITypeBuilder _typeBuilder;     
        private readonly Type _viewType;
        private readonly Type _viewModelType;

        internal ViewModelProvider(ITypeBuilder typeBuilder, Type viewType, Type viewModelType)
        {
            Guard.ArgumentNotNull(typeBuilder, "typeBuilder");
            Guard.ArgumentNotNull(viewType, "viewType");

            _typeBuilder = typeBuilder;
            _viewType = viewType;
            _viewModelType = viewModelType;
        }

#region IViewModelProvider Implementation

        public Object CreateViewInstance()
        {
            return _typeBuilder.BuildType(_viewType);
        }

        public Object CreateViewModelInstance()
        {
            return (_viewModelType != null) ? _typeBuilder.BuildType(_viewModelType) : null;
        }

#endregion

    }
}
